package au.edu.unsw.infs3634.gamifiedlearning.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import au.edu.unsw.infs3634.gamifiedlearning.R;
import au.edu.unsw.infs3634.gamifiedlearning.model.SendModel;

public class JoinAdapter extends RecyclerView.Adapter<JoinAdapter.JoinHolder> {

    private List<String> meetingList;

    private View view;

    public JoinAdapter(List<String> meetingList) {
        this.meetingList = meetingList;
    }

    @NonNull
    @Override
    public JoinAdapter.JoinHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_join, parent, false);
        JoinHolder joinHolder = new JoinHolder(view);
        return joinHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull JoinAdapter.JoinHolder holder, int position) {
        String meetingName = meetingList.get(position);
        holder.meetingName.setText(meetingName);

        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onItemListener.onClick(meetingName);
            }
        });
    }

    @Override
    public int getItemCount() {
        return meetingList.size();
    }


    class JoinHolder extends RecyclerView.ViewHolder {

        private TextView meetingName;


        public JoinHolder(@NonNull View itemView) {
            super(itemView);
            this.meetingName = itemView.findViewById(R.id.join_meeting_name);
        }
    }

    private OnItemListener onItemListener;

    public void setOnItemListener(JoinAdapter.OnItemListener onItemListener) {
        this.onItemListener = onItemListener;
    }

    public interface OnItemListener {
        void onClick(String meetingName);
    }
}
